<?php

include './common/functions.php';
include_once './common/Db.class.php';

$data = $_POST;

$password = md5($data['password']);

// 链接数据库
$db = new Db('user');
// 加where条件
$db->where("username='{$data['username']}' and password='{$password}'");

$res = $db->select();

if($res){
	session_start();

	$_SESSION['username'] = $data['username'];
	$_SESSION['uid'] = $res[0]['uid'];

	exit(json_encode(['code'=>0,'msg'=>"登陆成功"]));
}else{
	exit(json_encode(['code'=>1,'msg'=>"用户名与密码错误"]));
}